package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.View;
	import engine.data.ViewObject;
	
	import newx.BaseObject;

	public class CheckModifiedEnableLogic
	{
		private static var  _self:CheckModifiedEnableLogic;
		private var _enable:int;
		private var _model:ModelLocator
		/**装备视图数组*/
		private var _equipViewArray:Array;
		private var _equipItemArray:Array;
		private var _viewItemArray:Array;
		private var _friendListObj:Object;
		public function CheckModifiedEnableLogic()
		{
			_model			=	ModelLocator.getInstance();
			_equipItemArray	=	[];
		}
		public static function getInstance():CheckModifiedEnableLogic
		{
			if(_self == null)
			{
				_self	=	new CheckModifiedEnableLogic();
			}
			return _self;
		}
		/**
		 * 是否有可强化装备
		 * @return
		 * 
		 */		
		public function get checkGuide():int
		{
			_enable	=	-1;;
			var needMoney:Number
			var item	:BaseObject
			_equipItemArray	=	getEquipItem();
			
			for(var i:int = 0; i< _equipItemArray.length; i++)
			{
				item	=	_equipItemArray[i] as BaseObject;
				if(item.GetProperties("IntensityLevel") < _model.scene.Role.getPlayerLevel())
				{
					needMoney	=	EquipModifiedLogic.getInstance().getNeedMoney(int(item.GetProperties("IntensityLevel") + 1),int(item.GetProperties("Color")),item.GetProperties("EquipType"))
					if(_model.scene.Role.getGoldCoin() > needMoney)
					{
						_enable	=	1;
						break;
					}
				}
			}
			return _enable;
		}
		/**
		 *  获取所有装备
		 * @return
		 * 
		 */		
		private function getEquipItem():Array
		{
			_equipViewArray	=	[];
			var tempArray:Array	=	[];
			var checkItem:Array	=	[];
			//玩家背包视图号
			_equipViewArray.push(View.VIEWPORT_EQUIP);
			_friendListObj	=	_model.scene.GetView(View.VIEWPORT_PARTNER)["Properties"] as Object;
			
			for(var item:String in _friendListObj)
			{
				if(_friendListObj[item] is ViewObject)
				{
					_equipViewArray.push(EquipModifiedLogic.getInstance().getEquipView((_friendListObj[item] as BaseObject).GetProperties("ConfigID")));
				}
			}
			for(var i:int = 0; i < _equipViewArray.length; i++)
			{
				checkItem	=	getViewItem(_equipViewArray[i])
				for(var m:int = 0; m < checkItem.length; m++)
				{
					tempArray.push(checkItem[m]);
				}
			}
			return tempArray;
		}
		/**
		 * 获取指定视图中的所有的装备
		 * @param viewID
		 * 
		 */		
		private function getViewItem(viewID:int):Array
		{
			_viewItemArray	=	[];
			var view:View	=	_model.scene.GetView(viewID)
			if(view == null)
			{
				return [];
			}
			var tempObj:Object	=	view["Properties"] as Object;
			for(var item:String in tempObj)
			{
				if(tempObj[item] is ViewObject)
				{
					_viewItemArray.push(tempObj[item] as BaseObject);
				}
			}
			return _viewItemArray;
			
		}
	}
}